const {Solar, SolarUtil, HolidayUtil} = require('lunar-javascript')

//获取指定年的假期数量，参数year:年份，例2022
function getHolidaySum(year) {
    let HolidaySum = 0; //记录假期数量
    for(let month = 1;month <=12 ;month++) { //12个月
        let dayNums = SolarUtil.getDaysOfMonth(year, month); //获取该月天数
        for(let day = 1;day <= dayNums; day++) { //检测天
            let d = HolidayUtil.getHoliday(year, month, day);
            if(d) { //是法定 节假日 或 调休日
                HolidaySum++;
                console.log(d.getDay() + " " + d.getName() + (d.isWork()?"调休":"放假"));
            } else {
                //判断星期
                d = Solar.fromYmd(year, month, day)
                let week = d.getWeek();
                if(week == 0 || week == 6) {
                    HolidaySum++;
                    console.log(d.toYmd() + " 双休");
                }
            }
        }
    }
    return HolidaySum;
}


//var startTimeJs = Date.now();
/* 执行输出 */
let s = getHolidaySum(2022);
//var endTimeJs = Date.now();
//console.log("用时: " + (endTimeJs - startTimeJs)/1000 + "s : js");
console.log(s);